package com.vsd.service.impl;

import java.util.Collection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.demo.util.SqlUtils;
import com.shopcart.domain.StorePhoto;
import com.vsd.repository.StorePhoneRepository;
import com.vsd.service.StorePhotoService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Service
@Transactional
public class StorePhotoServiceImpl implements StorePhotoService {

	@SuppressWarnings("unused")
	private static final Logger LOGGER = LoggerFactory
			.getLogger(StorePhotoServiceImpl.class);
	
	@Autowired
	JdbcTemplate jdbcTemplate;
	
	@Autowired
	private StorePhoneRepository storePhoneRepository;

	@Override
	public Collection<StorePhoto> findByStoreId(String storeId) {
		// TODO Auto-generated method stub
		return storePhoneRepository.findByStoreId(storeId, new Sort(Direction.DESC, "createTime"));
	}

	@Override
	public Page<StorePhoto> findByStoreId(String storeId, Pageable p) {
		// TODO Auto-generated method stub
		return storePhoneRepository.findByStoreId(storeId, p);
	}

	@Override
	public StorePhoto findOne(String id) {
		// TODO Auto-generated method stub
		return storePhoneRepository.findOne(id);
	}

	@Override
	public void save(StorePhoto s) {
		// TODO Auto-generated method stub
		storePhoneRepository.save(s);
	}

	@Override
	public void delById(String id) {
		// TODO Auto-generated method stub
		storePhoneRepository.delete(id);
	}

	@Override
	public int updateByPrimaryKeySelective(StorePhoto s) {
		// TODO Auto-generated method stub
		try {
			String sql = SqlUtils.update(s, true, " where id = '"+s.getId()+"'");
			return jdbcTemplate.update(sql);
		}  catch (Exception e) {
			// TODO Auto-generated catch block
			return 0;
		}
	}
 
 

	
}
